home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src / httrack.h < prev    next >
C/C++ Source or Header  |  2006-08-15  |  7KB  |  249 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: htsshow.c console progress info                        */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. #ifndef HTSTOOLS_DEFH
  38. #define HTSTOOLS_DEFH 
  39.  
  40. #include "htsglobal.h"
  41. #include "htscore.h"
  42.  
  43. #ifndef HTS_DEF_FWSTRUCT_t_StatsBuffer
  44. #define HTS_DEF_FWSTRUCT_t_StatsBuffer
  45. typedef struct t_StatsBuffer t_StatsBuffer;
  46. #endif
  47. struct t_StatsBuffer {
  48.   char name[1024];
  49.   char file[1024];
  50.   char state[256];
  51.   char BIGSTK url_sav[HTS_URLMAXSIZE*2];    // pour cancel
  52.   char BIGSTK url_adr[HTS_URLMAXSIZE*2];
  53.   char BIGSTK url_fil[HTS_URLMAXSIZE*2];
  54.   LLint size;
  55.   LLint sizetot;
  56.   int offset;
  57.   //
  58.   int back;
  59.   //
  60.   int actived;    // pour disabled
  61. };
  62.  
  63. #ifndef HTS_DEF_FWSTRUCT_t_InpInfo
  64. #define HTS_DEF_FWSTRUCT_t_InpInfo
  65. typedef struct t_InpInfo t_InpInfo;
  66. #endif
  67. struct t_InpInfo {
  68.   int ask_refresh;
  69.   int refresh;
  70.   LLint stat_bytes;
  71.   int stat_time;
  72.   int lien_n;
  73.   int lien_tot;
  74.   int stat_nsocket;
  75.   int rate;
  76.   int irate;
  77.   int ft;
  78.   LLint stat_written;
  79.   int stat_updated;
  80.   int stat_errors;
  81.   int stat_warnings;
  82.   int stat_infos;
  83.   TStamp stat_timestart;
  84.   int stat_back;
  85. };
  86.  
  87. int main(int argc, char **argv);
  88. #endif
  89.  
  90. /* */
  91.  
  92. // Engine internal variables
  93. typedef void (* htsErrorCallback)(char* msg, char* file, int line);
  94. extern HTSEXT_API htsErrorCallback htsCallbackErr;
  95. extern HTSEXT_API int htsMemoryFastXfr;
  96. /* */
  97. extern HTSEXT_API hts_stat_struct HTS_STAT;
  98. extern int _DEBUG_HEAD;
  99. extern FILE* ioinfo;
  100.  
  101. // from htsbase.h
  102.  
  103. /* protected strcat, strncat and strcpy - definitely useful */
  104. #define strcatbuff(A, B) do { \
  105.   assertf( (A) != NULL ); \
  106.   if ( ! (B) ) { assertf( 0 ); } \
  107.   if (htsMemoryFastXfr) { \
  108.     if (sizeof(A) != sizeof(char*)) { \
  109.       (A)[sizeof(A) - 1] = '\0'; \
  110.     } \
  111.     strcat(A, B); \
  112.     if (sizeof(A) != sizeof(char*)) { \
  113.       assertf((A)[sizeof(A) - 1] == '\0'); \
  114.     } \
  115.   } else { \
  116.     unsigned int sz = (unsigned int) strlen(A); \
  117.     unsigned int szf = (unsigned int) strlen(B); \
  118.     if (sizeof(A) != sizeof(char*)) { \
  119.       assertf(sz + szf + 1 < sizeof(A)); \
  120.       if (szf > 0) { \
  121.         if (sz + szf + 1 < sizeof(A)) { \
  122.           memcpy((A) + sz, (B), szf + 1); \
  123.         } \
  124.       } \
  125.     } else if (szf > 0) { \
  126.       memcpybuff((A) + sz, (B), szf + 1); \
  127.     } \
  128.   } \
  129. } while(0)
  130. #define strncatbuff(A, B, N) do { \
  131.   assertf( (A) != NULL ); \
  132.   if ( ! (B) ) { assertf( 0 ); } \
  133.   if (htsMemoryFastXfr) { \
  134.     if (sizeof(A) != sizeof(char*)) { \
  135.       (A)[sizeof(A) - 1] = '\0'; \
  136.     } \
  137.     strncat(A, B, N); \
  138.     if (sizeof(A) != sizeof(char*)) { \
  139.       assertf((A)[sizeof(A) - 1] == '\0'); \
  140.     } \
  141.   } else { \
  142.     unsigned int sz = (unsigned int) strlen(A); \
  143.     unsigned int szf = (unsigned int) strlen(B); \
  144.     if (szf > (unsigned int) (N)) szf = (unsigned int) (N); \
  145.     if (sizeof(A) != sizeof(char*)) { \
  146.       assertf(sz + szf + 1 < sizeof(A)); \
  147.       if (szf > 0) { \
  148.         if (sz + szf + 1 < sizeof(A)) { \
  149.           memcpy((A) + sz, (B), szf); \
  150.           * ( (A) + sz + szf) = '\0'; \
  151.         } \
  152.       } \
  153.     } else if (szf > 0) { \
  154.       memcpybuff((A) + sz, (B), szf); \
  155.       * ( (A) + sz + szf) = '\0'; \
  156.     } \
  157.   } \
  158. } while(0)
  159. #define strcpybuff(A, B) do { \
  160.   assertf( (A) != NULL ); \
  161.   if ( ! (B) ) { assertf( 0 ); } \
  162.   if (htsMemoryFastXfr) { \
  163.     if (sizeof(A) != sizeof(char*)) { \
  164.       (A)[sizeof(A) - 1] = '\0'; \
  165.     } \
  166.     strcpy(A, B); \
  167.     if (sizeof(A) != sizeof(char*)) { \
  168.       assertf((A)[sizeof(A) - 1] == '\0'); \
  169.     } \
  170.   } else { \
  171.     unsigned int szf = (unsigned int) strlen(B); \
  172.     if (sizeof(A) != sizeof(char*)) { \
  173.       assertf(szf + 1 < sizeof(A)); \
  174.       if (szf > 0) { \
  175.         if (szf + 1 < sizeof(A)) { \
  176.           memcpy((A), (B), szf + 1); \
  177.         } else { \
  178.           * (A) = '\0'; \
  179.         } \
  180.       } else { \
  181.         * (A) = '\0'; \
  182.       } \
  183.     } else { \
  184.       memcpybuff((A), (B), szf + 1); \
  185.     } \
  186.   } \
  187. } while(0)
  188.  
  189. // emergency log
  190. typedef void (*t_abortLog)(char* msg, char* file, int line);
  191. extern HTSEXT_API t_abortLog abortLog__;
  192. #define abortLog(a) abortLog__(a, __FILE__, __LINE__)
  193. #define abortLogFmt(a) do { \
  194.   FILE* fp = fopen("CRASH.TXT", "wb"); \
  195.   if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \
  196.   if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \
  197.   if (fp) { \
  198.     fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \
  199.     fprintf(fp, "Reason:\r\n"); \
  200.     fprintf(fp, a); \
  201.     fprintf(fp, "\r\n"); \
  202.     fflush(fp); \
  203.     fclose(fp); \
  204.   } \
  205. } while(0)
  206.  
  207. #define _ ,
  208. #define abortLogFmt(a) do { \
  209.   FILE* fp = fopen("CRASH.TXT", "wb"); \
  210.   if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \
  211.   if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \
  212.   if (fp) { \
  213.     fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \
  214.     fprintf(fp, "Reason:\r\n"); \
  215.     fprintf(fp, a); \
  216.     fprintf(fp, "\r\n"); \
  217.     fflush(fp); \
  218.     fclose(fp); \
  219.   } \
  220. } while(0)
  221. #define assertf(exp) do { \
  222.   if (! ( exp ) ) { \
  223.     abortLog("assert failed: " #exp); \
  224.     if (htsCallbackErr != NULL) { \
  225.       htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \
  226.     } \
  227.     assert(exp); \
  228.     abort(); \
  229.   } \
  230. } while(0)
  231. /* non-fatal assert */
  232. #define assertnf(exp) do { \
  233.   if (! ( exp ) ) { \
  234.     abortLog("assert failed: " #exp); \
  235.     if (htsCallbackErr != NULL) { \
  236.       htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \
  237.     } \
  238.   } \
  239. } while(0)
  240.  
  241. //
  242.  
  243. #define malloct(A)          malloc(A)
  244. #define calloct(A,B)        calloc((A), (B))
  245. #define freet(A)            do { assertnf((A) != NULL); if ((A) != NULL) { free(A); (A) = NULL; } } while(0)
  246. #define strdupt(A)          strdup(A)
  247. #define realloct(A,B)       ( ((A) != NULL) ? realloc((A), (B)) : malloc(B) )
  248. #define memcpybuff(A, B, N) memcpy((A), (B), (N))
  249.